package com.liu.ysy.config;

import com.liu.ysy.entity.AsyncPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration //配置类
@EnableAsync // 表示开启异步事件的支持

public class AsyncConfig {

    @Autowired
    private AsyncPool asyncPool;

    @Bean
    public Executor taskExecuter(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(asyncPool.getCorePoolSize());
        executor.setMaxPoolSize(asyncPool.getMaxPoolSize());
        executor.setQueueCapacity(asyncPool.getQueueCapacity());
        executor.initialize();
        return  executor;
    }


}
